package com.juc.scheduledExecutorService.scheduledExecutorService7;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;


public class Run {

	/**
	 * scheduleWithFixedDelay() 周期性执行
	 * 主要作用：设置多个任务之间固定的运行时间间隔
	 * 执行任务时间小于<period 预定时间
	 */
	public static void main(String[] args) {
		ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
	    System.out.println("  X= " + System.currentTimeMillis());
	    executorService.scheduleWithFixedDelay(new MyRunnable(), 1, 2, TimeUnit.SECONDS);
	    System.out.println("  Y= " + System.currentTimeMillis());
	}
}
